package com.bj58.groupbuy.action.service.impl;

import java.util.HashMap;
import java.util.List;

import com.bj58.groupbuy.action.db.CommonDao;
import com.bj58.groupbuy.action.db.DBConfig;
import com.bj58.groupbuy.action.model.NetFlowSource;
import com.bj58.groupbuy.action.service.NetFlowSourceService;

public class NetFlowSourceServiceImpl implements NetFlowSourceService {
	private CommonDao comDao = new CommonDao();
	
	@Override
	public List<NetFlowSource> getSource1List(String platform) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT *  ");
		sql.append(" FROM data_dict.t_common_netflow_source_bi ");
		sql.append(" where platform  ='"+platform+"'");
		sql.append(" and source1 is not null  group by source1");
		
		return comDao.getAllColsByVo(sql.toString(), NetFlowSource.class, DBConfig.db_131_data_bi.getIntType());
	}

	@Override
	public List<NetFlowSource> getSource2List(String source1)
			throws Exception {

		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT *  ");
		sql.append(" FROM data_dict.t_common_netflow_source_bi ");
		sql.append(" where ");
		sql.append(" source1 = '" + source1+"' ");
		sql.append(" and source2 is not null group by source2");
		
		return comDao.getAllColsByVo(sql.toString(), NetFlowSource.class, DBConfig.db_131_data_bi.getIntType());
	}

	@Override
	public List<NetFlowSource> getSource3List(String source1,
			String source2) throws Exception {
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT *  ");
		sql.append(" FROM data_dict.t_common_netflow_source_bi ");
		sql.append(" where  ");
		sql.append(" source1 = '" + source1+"' ");
		sql.append(" and source2 = '" + source2+"' ");
		sql.append(" and source3 is not null group by source3");
		
		return comDao.getAllColsByVo(sql.toString(), NetFlowSource.class, DBConfig.db_131_data_bi.getIntType());
	}

	@Override
	public List<NetFlowSource> getSource4List(String source1,
			String source2, String source3) throws Exception {
		
		StringBuffer sql = new StringBuffer();
		sql.append(" SELECT *  ");
		sql.append(" FROM data_dict.t_common_netflow_source_bi ");
		sql.append(" where ");
		sql.append(" source1 = '" + source1+"' ");
		sql.append(" and source2 = '" + source2+"' ");
		sql.append(" and source3 = '" + source3+"' ");
		sql.append(" and source4 is not null group by source4");
		
		return comDao.getAllColsByVo(sql.toString(), NetFlowSource.class, DBConfig.db_131_data_bi.getIntType());
	}


	@Override
	public HashMap<String, String> getDicMap()throws Exception {
		String sql = "select * from data_dict.t_common_netflow_source_bi ";
		List<NetFlowSource> tempList = comDao.getAllColsByVo(sql, NetFlowSource.class, DBConfig.db_131_data_bi.getIntType());
	
		HashMap<String, String> dicMap = new HashMap<String, String>();
		for (NetFlowSource vo : tempList) {
			String source1 = vo.getSource1();
			String source1_name = vo.getSource1_name();
			if(!dicMap.containsKey(source1) && null!= source1  && null != source1_name && !source1.equals(source1_name)){
				dicMap.put(source1, vo.getSource1_name());
			}
			
			String source2 = vo.getSource2();
			String source2_name = vo.getSource2_name();
			if(!dicMap.containsKey(source2) && null!= source2  && null != source2_name && !source2.equals(source2_name)){
				dicMap.put(source2, vo.getSource2_name());
			}
			
			String source3 = vo.getSource3();
			String source3_name = vo.getSource3_name();
			if(!dicMap.containsKey(source3) && null!= source3  && null != source3_name &&  !source3.equals(source3_name)){
				dicMap.put(source3, vo.getSource3_name());
			}
		}
		return dicMap;
	}
}
